package com.kawaiim.zhj.OutCard;

import java.util.ArrayList;
import java.util.List;

import com.kawaiim.zhj.entity.Card;
import com.kawaiim.zhj.entity.Player;

//提示出牌
public class PlayerRemindCard {

    //玩家任意出牌的游戏提示，记录上次找的牌
    public static void remindCard(Player player, List<Card> prevCard, boolean canOutBoom) {
        //判断上家的卡组样式
        OutCardStyle preOutCardStyle = OutCardStyle.judgeCardStyle(prevCard);
        //如果想出什么牌就出什么牌
        if (preOutCardStyle.outCardStyleEnum == OutCardStyleEnum.CANT_OUT) {
            player.htCards = new ArrayList<Card>();
            peopleFirstHint(player, true);
        }
        //打上一家出的牌（如果是打自己出的牌，canOutBoom=false）
        else {
            player.htCards = CrushPreCard.crushPreCard(player.cards, preOutCardStyle, canOutBoom, true);
        }
    }

    //玩家想出什么牌出什么牌的提示
    // 按各种可能性提示，第i+1次提示比第i次提示要不同类型大，要不提示下一种类型
    // 算法思想，伪造一个cardStyle，如果当前玩家能打，则可以出
    public static void peopleFirstHint(Player player, boolean canSplit) {
        List<Card> deck = player.cards;
        int length = player.cards.size();
        OutCardStyle createOutCardStyle;    //伪造一个outCardStyle，判断其能否出相应的牌

        switch (player.htStyle) {
            //如果是第一次提示（大的开始提示）
            case CANT_OUT:
            case NEXT_TWO:
                //todo 连对，对3-对A共24张
                for (int i = length / 2 * 2; i >= 6 && player.htCards.size() == 0; i -= 2) {
                    createOutCardStyle = new OutCardStyle(OutCardStyleEnum.NEXT_TWO, 0, i);
                    player.htCards = CrushPreCard.crushPreCard(deck, createOutCardStyle, false, canSplit);
                }
                player.htStyle = OutCardStyleEnum.STRAIGHT;
                //如果找到则跳出
                if (player.htCards.size() != 0) {
                    break;
                }

            case STRAIGHT:
                //顺子，3-A共12张
                for (int cardLen = Math.min(12, length); cardLen >= 5 && player.htCards.size() == 0; cardLen--) {
                    createOutCardStyle = new OutCardStyle(OutCardStyleEnum.STRAIGHT, 0, cardLen);
                    player.htCards = CrushPreCard.crushPreCard(deck, createOutCardStyle, false, canSplit);
                }
                player.htStyle = OutCardStyleEnum.TWO;
                //如果找到则跳出
                if (player.htCards.size() != 0) {
                    break;
                }

            case TWO:
                createOutCardStyle = new OutCardStyle(OutCardStyleEnum.TWO, 0, 2);
                player.htCards = CrushPreCard.crushPreCard(deck, createOutCardStyle, false, canSplit);
                player.htStyle = OutCardStyleEnum.ONE;
                //如果找到则跳出
                if (player.htCards.size() != 0) {
                    break;
                }

            case ONE:
                createOutCardStyle = new OutCardStyle(OutCardStyleEnum.ONE, 0, 1);
                player.htCards = CrushPreCard.crushPreCard(deck, createOutCardStyle, false, canSplit);
                player.htStyle = OutCardStyleEnum.BOMB;
                //如果找到则跳出
                if (player.htCards.size() != 0) {
                    break;
                }

            case BOMB:

                createOutCardStyle = new OutCardStyle(OutCardStyleEnum.BOMB, 0, 3);
                player.htCards = CrushPreCard.crushPreCard(deck, createOutCardStyle, false, canSplit);

                player.htStyle = OutCardStyleEnum.LIGHTNING;
                //如果找到则跳出
                if (player.htCards.size() != 0) {
                    break;
                }
            case LIGHTNING:
                if (OutCardStyle.isLightning(player.cards) != 0) {
                    player.htCards = player.cards;
                }
                player.htStyle = OutCardStyleEnum.CANT_OUT;
                break;
            default:
                break;
        }
    }


}
